<?php



namespace App\Services\Business\Services;

use App\Services\Member\Interfaces\ActivityServiceInterface;
use App\Services\Business\Models\Decorate;
use App\Services\Member\Models\Activity;

class ActivityService implements ActivityServiceInterface
{




    /**
     *
     * @param array $userIds
     * @param int $page
     * @param int $size
     */
    public
    function  getAuthorize(int $manageId, int $processId, array $status, int $companyId, string $keywords, array $userIds, int $size)
    {


        $decorateIds =   Decorate::query()->where('manage_id',$manageId)->pluck('id')->toArray();
       return Activity::query()
            ->with(['decorate:id,remark_name,created_at','user:id,nick_name,mobile,avatar','customer:id,nick_name,mobile,avatar','images','videos','process'])
           ->when($keywords, function ($query) use ($keywords) {
               $customerIds =   Decorate::query()->where('remark_name', 'like', '%' . $keywords . '%')->get()->pluck('id')->toArray();
               $query->whereIn('customer_id',$customerIds);
           })
           //发布动态的人
           ->when($userIds, function ($query) use ($userIds) {
               $query->whereIn('user_id',$userIds);
           })
           ->when($processId, function ($query) use ($processId) {
               $query->where('process_id',$processId);
           })
           ->when($status, function ($query) use ($status) {
               $query->whereIn('status',$status);
           })
           ->when($status, function ($query) use ($status) {
               $query->where('status','<>',2);
           })
           ->whereIn('decorate_id',$decorateIds)
           //审核的人
           ->where('company_id',$companyId)
            ->orderByDesc('created_at')
            ->paginate($size);

    }

    public     function  getSubmission(int $userId, int $status, int $companyId, string $keywords, int $size)
    {

        return Activity::query()
            ->with(['decorate:id,remark_name,created_at','user:id,nick_name,mobile,avatar','customer:id,nick_name,mobile,avatar','images','videos','process:id,title,description'])
            ->when($keywords, function ($query) use ($keywords) {
                $customerIds =   Decorate::query()->where('remark_name', 'like', '%' . $keywords . '%')->get()->pluck('id')->toArray();
                $query->whereIn('customer_id',$customerIds);
            })

            ->when($status, function ($query) use ($status) {
                $query->where('status',$status);
            })
            ->orderByDesc('updated_at')
            ->where('user_id',$userId)
            ->where('company_id',$companyId)
            ->orderByDesc('created_at')
            ->paginate($size);

    }



}
